package com.example.bysj_sb.dao;

import com.example.bysj_sb.domain.authority.Actor;
import com.example.bysj_sb.service.StudentService;
import com.example.bysj_sb.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("actorDao")
public class ActorDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private StudentService studentService;
    @Autowired
    private TeacherService teacherService;
    //增加
    public boolean add() {
        //actor表中只有自增id字段，不需要参数
        String sql = "INSERT INTO actor () VALUES ()";
        int affectedRowNum = jdbcTemplate.update(sql);
        if (affectedRowNum != 1) {
            return false;
        } else {

            return true;
        }
    }
   //根据id查询
    public Actor find(int id){
        //先后在Student和Teacher中查找相应的id
        Actor desiredActor = null;
        //查询id对应的Student对象
        desiredActor = studentService.find(id);
        if (desiredActor != null) {
            return desiredActor;
        }
        //查询id对应的Teacher对象
        desiredActor = teacherService.find(id);
        return desiredActor;
    }

}